package edu.hda.pt.utils.connections.mina.codec;

import org.apache.mina.core.session.IoSession;
import org.apache.mina.filter.codec.ProtocolCodecFactory;
import org.apache.mina.filter.codec.ProtocolDecoder;
import org.apache.mina.filter.codec.ProtocolEncoder;

/**
 * Codec factory for providing the encoder and decoder
 * 
 * @author Marc Hammerton
 *
 */
public class CodecFactory implements ProtocolCodecFactory {
	
	private ProtocolEncoder encoder;
    private ProtocolDecoder decoder;
    
    /**
     * Constructor, creating a new encoder and decoder
     * @see edu.hda.pt.utils.connections.mina.codec.MessageEncoder
     * @see edu.hda.pt.utils.connections.mina.codec.MessageDecoder
     */
    public CodecFactory() {
    	encoder = new MessageEncoder();
    	decoder = new MessageDecoder();
    	
    }

	/**
	 * @see org.apache.mina.filter.codec.ProtocolCodecFactory#getDecoder(org.apache.mina.core.session.IoSession)
	 */
	@Override
	public ProtocolDecoder getDecoder(IoSession arg0) throws Exception {
		return decoder;
	}

	/**
	 * @see org.apache.mina.filter.codec.ProtocolCodecFactory#getEncoder(org.apache.mina.core.session.IoSession)
	 */
	@Override
	public ProtocolEncoder getEncoder(IoSession arg0) throws Exception {
		return encoder;
	}

}
